
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __USER_COMM_UTIL_H
#define __USER_COMM_UTIL_H

#ifdef __cplusplus
extern "C" {
#endif

/* Includes ------------------------------------------------------------------*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/* Exported types ------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
/* Exported macro ------------------------------------------------------------*/

/*!< 得到指定地址上的一个字节或字 <<<<<<<<<<<<<<<<<<<<<<<<<*/
#define  Mem_B( x )             (*((unsigned char *) (x)))
#define  Mem_W( x )             (*((unsigned short *)(x)))

/*!< 求最大值和最小值 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
#define  Max(x, y)              (((x) > (y)) ? (x) : (y))
#define  Min(x, y)              (((x) < (y)) ? (x) : (y))

/*!< 得到一个变量的地址（word宽度） <<<<<<<<<<<<<<<<<<<<<<*/
#define  B_Ptr(var)             ((unsigned char *)  (void *)&(var))
#define  W_Ptr(var)             ((unsigned short *) (void *)&(var))

/*!< 返回数组元素的个数 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
#define  ArraySize(a)           (sizeof (a) / sizeof (a[0]))

/*!< 得到一个field在结构体(struct)中的偏移量 <<<<<<<<<<<<<<*/
#define  FOffset(type, field)   ((unsigned int)(&(((type *)0)->field)))

#define  Offset(TYPE, MEMBER, OFF) \
    TYPE temp; \
    OFF = (unsigned int)(&(temp.MEMBER)) - (unsigned int)(&(temp));

/*!< 得到一个结构体中field所占用的字节数 <<<<<<<<<<<<<<<<<<*/
#define  FSize(type, field)     sizeof(((type *)0)->field)

/*!< 得到一个字的高位和低位字节 <<<<<<<<<<<<<<<<<<<<<<<<<<*/
#define  GET_WORD_L(word)       ((unsigned char)(((unsigned short)(word)) & 255))
#define  GET_WORD_H(word)       ((unsigned char)(((unsigned short)(word)) >> 8))

#define  MAKE_WORD(L, H)        (unsigned short) (((unsigned char)(((unsigned short)(L)) & 0xFF)) | ((unsigned short)((unsigned char)(((unsigned short)(H)) & 0xFF))) << 8)

/* Exported variables --------------------------------------------------------*/
/* Exported functions ------------------------------------------------------- */

#ifdef __cplusplus
}
#endif

#endif /* __USER_COMM_UTIL_H */

/* END OF FILE ---------------------------------------------------------------*/
